/**
 * Created by chengming on 18/5/27.
 * version 1.0
 */
const ArticleHrefAdapter = require('../ArticleHrefAdapter');
const cheerio = require('cheerio');
const urlTool = require('url');

/**
 * 上海有色
 * @type {module.Bjp2p}
 */
module.exports = class SMMnews extends ArticleHrefAdapter {


  parseHtml(html, linkRule) {
    //将解析后的内容加载进解析器
    let $ = cheerio.load(html);
    let contents = [];
    let rangeText = '';
    let encoding = this.encoding;
    let that = this
    $(this.linkRule).each(function () {
      let liHtml = $(this).html();
      let $$ = cheerio.load(liHtml);
      let href = $$('a').first().attr('href')
      href = urlTool.resolve(that.requestUrl, href)
      let title = $$('a').first().find('h3').first().text()
      contents.push({
        title: title,
        href: href
      });
      rangeText += title + href;
    });
    return {
      rangeText: rangeText,
      contents: contents
    };
  }


}
